package com.taro.apise.indexer.config;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


@Configuration
public class AppConfig {

    //创建线程池
    @Bean
    public ExecutorService executorService(){
        //一共8个线程，最多20个线程，超市时间30，线程队列
        ThreadPoolExecutor executor = new ThreadPoolExecutor(8 , 20 , 30 , TimeUnit.SECONDS ,
                new ArrayBlockingQueue<>(5000) , (Runnable task) -> {
            Thread thread = new Thread(task);
            thread.setName("批量插入线程");
            return thread;
        }, new ThreadPoolExecutor.AbortPolicy());
        return executor;
    }
}
